package com.wenfs.demo.service.impl;

import com.wenfs.demo.dao.SysRoleMapper;
import com.wenfs.demo.entity.SysRole;
import com.wenfs.demo.service.ISysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * @author wefashe
 */
@Service
public class SysRoleBo implements ISysRole {
  @Autowired
  private SysRoleMapper sysRoleMapper;

  @Override
  public Set<String> getRoleCodesByUserCode(String userCode) {
    return sysRoleMapper.getRoleCodesByUserCode(userCode);
  }

  @Override
  public int save(SysRole role) {
    role.setRodeId(UUID.randomUUID().toString());
    Integer maxCode = sysRoleMapper.getMaxCode();
    role.setRoleCode(String.valueOf(maxCode + 1));
    role.setCreateTime(String.valueOf(System.currentTimeMillis()));
    role.setUpdateTime(String.valueOf(System.currentTimeMillis()));
    role.setRoleStatus((byte) 1);
    return sysRoleMapper.save(role);
  }



  @Override
  public void setStatus(Integer status, String roleCode) {
    sysRoleMapper.setStatus(status,roleCode);
  }

  @Override
  public List<SysRole> findAll() {
    return sysRoleMapper.findAll();
  }
}
